<cfcomponent hint="I provide the settings for the wiki" output="false" extends="com.wikifusion.utils.audit">
	
	<cffunction name="init" output="false" returntype="any" hint="instantiates an object of this class" access="public">
		<cfargument name="applicationname" required="true" type="string">
		<cfscript>
			
			if (not structkeyexists(this,"instance#arguments.applicationname#")) {
				this.applicationname = arguments.applicationname;
				this["instance#this.applicationname#"] = structnew();
				this["instance#this.applicationname#"].applicationname = arguments.applicationname;	
				this["instance#this.applicationname#"].count = 1;					
			}		  
		</cfscript>
			
		<cfreturn this />			
	</cffunction>
		
	<cffunction name="getWikiDatabaseObj" output="false" returntype="struct" hint="instantiates an object of this class" access="public">
		<cfargument name="configfilepath" required="true" type="string">
		<cfargument name="applicationname" type="string" default="#this.applicationname#">
		<cfset local = structnew()>		

		<cfif not fileexists(arguments.configfilepath)>
			<cfthrow type="MissingConfigFile" errorcode="MissingConfigFile" detail="Configuration file could not be read">
		</cfif>
		
		<cfif not structkeyexists(this["instance#arguments.applicationname#"],"datasourceOBJ")>
			<cfset this["instance#arguments.applicationname#"].datasourceOBJ = structnew()>
			<cfset local.args = structnew()>
			<cfset local.args.iniFile = arguments.configfilepath>
			<cfset local.args.sections = getProfileSections(local.args.iniFile)>
			<cfset this["instance#arguments.applicationname#"].count++>
			<cfif structKeyExists(local.args.sections, "#arguments.applicationname#")>
				<cfloop index="key" list="#local.args.sections[arguments.applicationname]#">
					<cfset this["instance#arguments.applicationname#"].datasourceOBJ[key] = getProfileString(local.args.iniFile, this["instance#arguments.applicationname#"].applicationname, key)>
				</cfloop>	
			<cfelseif structKeyExists(local.args.sections, "default")>
				<cfloop index="key" list="#local.args.sections.default#">
					<cfset this["instance#arguments.applicationname#"].datasourceOBJ[key] = getProfileString(local.args.iniFile, this["instance#arguments.applicationname#"].applicationname, key)>
				</cfloop>					
			</cfif>
		</cfif>
		
		<cfreturn this["instance#arguments.applicationname#"].datasourceOBJ> 
	</cffunction>	
	
	<cffunction name="loadWikiData" output="false" returntype="any" hint="get the wikis data" access="public">
		<cfargument name="applicationname" type="string" default="#this.applicationname#">
		<cfset local = structnew()>
		
		<cfquery name="local.qryWikiData" datasource="#this["instance#arguments.applicationname#"].datasourceOBJ.dsn#" username="#this["instance#arguments.applicationname#"].datasourceOBJ.username#" password="#this["instance#arguments.applicationname#"].datasourceOBJ.password#">
			SELECT	WikiID
					, WikiName
					, WikiDescription
					, WikiBasePath
					, WikiUrl
					, WikiSkin
					, WikiDSN
					, DatabasePrefix
					, UploadEnabled
					, WikiCreateDate
					, Plugins
					, WikiPlugins
					, WikiActive
			FROM	#this["instance#arguments.applicationname#"].datasourceOBJ.tablePrefix#wiki
			WHERE 	1 = 1
				AND WikiName = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.applicationname#">
		</cfquery>
	
		<cfset setVar(applicationname=arguments.applicationname,qryOBJ=local.qryWikiData)>
		
		<cfreturn true>
	</cffunction>
	
	<cffunction name="setVar" output="false" returntype="boolean" hint="dynamically sets the variables " access="public">
		<cfargument name="varname" required="false" type="string">
		<cfargument name="varvalue" required="false" type="string">
		<cfargument name="qryOBJ" required="false" type="query">
		<cfargument name="applicationname" type="string" default="#this.applicationname#">
		
		<cfif structkeyexists(arguments, "varname") and len(arguments.varname)>
			<cfset this["instance#arguments.applicationname#"][arguments.varname] = arguments.varvalue>
		<cfelseif isquery(arguments.qryOBJ)>		
			<cfloop array="#ARGUMENTS.qryOBJ.GetColumnNames()#" index="i">
				<cfset this["instance#arguments.applicationname#"][i] = ARGUMENTS.qryOBJ[i]>
			</cfloop>
		</cfif>	
		
		<cfreturn true>
	</cffunction>
	
	<cffunction name="getVar" output="false" returntype="Any" hint="dynamically returns the variables" access="public">		
		<cfargument name="varname" required="true" type="string">
		<cfargument name="applicationname" type="string" default="#this.applicationname#">
		
		<cfreturn this["instance#arguments.applicationname#"][arguments.varname]>
	</cffunction>
	
	<cffunction name="getVars" output="false" returntype="Any" hint="dynamically returns the variables" access="public">
		<cfargument name="applicationname" type="string" default="#this.applicationname#">		
	
		<cfreturn this["instance#arguments.applicationname#"]>
	</cffunction>

</cfcomponent>